package com.yuntsg.nnsfcp.common.utils;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 工具类操作String类型的公共方法类
 */
public class StringUtil {

    /**
     * 判断字符串是否为空或null
     */
    public static boolean isEmpty(CharSequence cs) {
        return org.apache.commons.lang3.StringUtils.isEmpty(cs);
    }

    public static boolean isNull(Object ss) {
        if (ss == null || ss.toString().equals("")) {
            return true;
        } else {
            return false;
        }
    }


    public static Map<String, Integer> strMapSortValueInt(Map<String, Integer> mapName, int limit) {
        Map<String, Integer> result = new LinkedHashMap<>();
        mapName.entrySet().stream()
                .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()).limit(limit)
                .forEachOrdered(e -> result.put(e.getKey(), e.getValue()));
        return result;
    }

    public static boolean isNotNull(Object ss) {
        if (ss == null || ss.toString().equals("")) {
            return false;
        } else {
            return true;
        }
    }

    public static void main(String[] args) {
        String A = "1";
        boolean notNull = isNotNull(A);
        System.out.println(notNull);

    }

    public static boolean ObjectIsNotNull(Object o) {
        if (o == null || o.toString().equals("") || o.toString().equals("null")) {
            return false;
        } else {
            return true;
        }
    }

    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.size() == 0;
    }

    public static boolean ObjectIsNull(Object o) {
        if (o == null || o.toString().equals("") || o.toString().equals("null")) {
            return true;
        } else {
            return false;
        }
    }
}
